<template>
  <div class="logon">
    <h3>面经登录</h3>
    <hr />
    <form v-if="isShow">
      <div class="input-group">
        用户名
        <input
          type="text"
          id="username"
          v-model="username"
          placeholder="用户名"
        />
      </div>
      <hr />
      <div class="input-group">
        <label for="password">密码</label>
        <input
          type="password"
          id="password"
          placeholder="密码"
          v-model="password"
        />
      </div>
      <hr />
    </form>
    <div v-else>
      <van-cell-group>
        <van-field
          v-model="username"
          error
          label="用户名"
          placeholder="用户名"
          error-message="请填写用户名"
        />
        <hr />

        <van-field
          v-model="password"
          error
          label="密码"
          placeholder="密码"
          error-message="请填写密码"
        />
        <hr />
      </van-cell-group>
    </div>
    <button type="submit" @click="fn">注册</button>
    <span @click="hh">有账号, 去登录</span>
  </div>
</template>

<script>
export default {
  data() {
    return {
      username: "",
      password: "",
      isShow: true,
    };
  },
  methods: {
    fn() {
      if (this.username.trim() === "" || this.username.length <= 6) {
        this.isShow = false;
      } else if (this.password.trim() === "" || this.password.length < 6) {
        this.isShow = false;
      } else if (this.password.trim() !== "" && this.username.trim() !== "") {
        this.isShow = true;
        // console.log("提交成功");
        this.$router.push({ path: "/logon" });
        this.password = "";
        this.username = "";
      }
    },
    hh() {
      this.$router.push({ path: "/logon" });
    },
  },
};
</script>

<style scoped lang="less">
h3 {
  text-align: center;
}
.logon {
  max-width: 400px;
  margin: 0 auto;
  padding: 20px;
}

.input-group {
  margin-bottom: 15px;
}

input[type="text"],
input[type="password"] {
  padding: 8px;
  /* box-sizing: border-box; */
  border: none;
  margin-left: 30px;
  outline: none;

  height: 30px;
}

input[type="password"] {
  margin-left: 50px;
}
button {
  width: 100%;
  padding: 10px;
  background-color: green;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  margin-top: 10px;
}

from {
  padding: 0 10px;
}
span {
  color: #0056b3;
  margin-top: 10px;
  float: right;
}
</style>
